// mypage/cashRecords/cashRecords.js
var util=require("../../utils/util")
var my=require("../../api/my")

Page({
  /*页面的初始数据*/
  data: {
    records: [],
    currentPage: 1,
    pageSize: 20,
    total: 0,
    token: '',
    show_none: false
  },
  /*生命周期函数--监听页面加载*/
  onLoad: function (options) {
    var that=this;
    that.setData({token:wx.getStorageSync('token')})
    that.get_record()
  },
  // 触底
  onReachBottom:function(){
    var that=this,total=that.data.total,records=that.data.records;
    if(records.length<total){
      that.setData({currentPage:that.data.currentPage+1})
      that.get_record()
    }else{
      util.page_show_toast('没有更多了',1500)
    }
  },
  get_record:function(){
    wx.showLoading()
    var that=this,cashRecords=that.data.records;
    var params={
      currentPage: that.data.currentPage,
      pageSize: that.data.pageSize,
    }
    my.walletCashRecords(params,that.data.token).then(res=>{
      wx.hideLoading()
      var {total,records}=res.data.data
      records.forEach(item=>{
        item.withdrawTime=item.withdrawTime?util.formatTime(new Date(item.withdrawTime)):util.formatTime(new Date())
      })
      // console.log(records)
      cashRecords.push(...records)
      that.setData({total:total,records:cashRecords})
      if(cashRecords.length==0&&records.length==0){
        that.setData({show_none:true})
      }
    })
  },
})